package com.educate.book.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.book.model.bo.BookCatalogueBO;
import com.educate.book.rpc.api.BookCatalogueService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("bookCatalogue")
public class BookCatalogueController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private BookCatalogueService bookCatalogueService;

    @PostMapping(value = "/create")
    public R create(@RequestBody BookCatalogueBO bo) {
        bookCatalogueService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody BookCatalogueBO bo) {
        bookCatalogueService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{bookCatalogueId}")
    public R delete(@PathVariable String bookCatalogueId) {
        bookCatalogueService.delete(bookCatalogueId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{bookCatalogueId}")
    public R<BookCatalogueBO> detail(@PathVariable String bookCatalogueId) {
        BookCatalogueBO bo = bookCatalogueService.detail(bookCatalogueId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<BookCatalogueBO> detail(@RequestBody BookCatalogueBO bo) {
        BookCatalogueBO detail = bookCatalogueService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<BookCatalogueBO> update(@RequestBody BookCatalogueBO bo) {
        bookCatalogueService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<BookCatalogueBO>> query(@RequestBody BookCatalogueBO bo) {
        Page<BookCatalogueBO> result = bookCatalogueService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<BookCatalogueBO>> list(@RequestBody BookCatalogueBO bo) {
        List<BookCatalogueBO> result = bookCatalogueService.list(bo);
        return R.ok(result);
    }

}
